<template>
  <div class="blind-box-card">
    <div class="blind-box-detail">
      <img
        :src="info.poster"
        alt=""
        @click="enterToBlindBoxDetail"
      >
      <van-swipe
        class="swipe-item-box"
        :autoplay="3000"
        :width="44"
        :height="44"
        :show-indicators="false"
        :loop="loop"
      >
        <van-swipe-item
          @click="onBlinkBoxImgClick(item)"
          v-for="(item,index) in info.prizes"
          :key="index"
        ><img
            :src="item.prize.poster"
            alt=""
          ></van-swipe-item>
      </van-swipe>
    </div>
    <span class="blink-box-title">{{info.name}}</span>
    <div class="prize-box">
      <span>￥</span>
      <span>{{info.price/100}}</span>
    </div>
  </div>
</template>

<script>
import { Swipe, SwipeItem } from "vant";
export default {
  name: "BlindBoxCardItem",
  components: {
    [Swipe.name]: Swipe,
    [SwipeItem.name]: SwipeItem,
  },
  props: {
    blindBoxInfo: {
      type: Object,
      default: () => {},
    },
  },
  watch: {
    blindBoxInfo: {
      deep: true,
      handler: function (newVal) {
        this.info = newVal;
      },
    },
  },
  computed: {
    loop: function () {
      let loop=false
      if (this.info.prizes.length>3) {
        loop=true
      }
      return loop;
    },
  },
  data() {
    return {
      info: {},
    };
  },
  created() {
    this.info = this.blindBoxInfo;
  },
  methods: {
    onBlinkBoxImgClick(item) {
      this.$emit("onBlinkBoxImgClick", this.info);
    },
    enterToBlindBoxDetail() {
      this.$emit("enterToBlindBoxDetail", this.info);
    },
  },
};
</script>

<style scoped lang="less">
.blind-box-card {
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
  .blind-box-detail {
    width: 100%;
    height: 422px;
    box-shadow: 0px 4px 8px 0px rgba(122, 151, 219, 0.5);
    border-radius: 24px;
    overflow: hidden;
    margin-top: 24px;
    position: relative;
    img {
      width: 100%;
      height: 422px;
      background: #d8d8d8;
    }
  }
  .swipe-item-box {
    width: 100%;
    height: 108px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 0px 0px 24px 24px;
    position: absolute;
    left: 0;
    bottom: 0;
    .van-swipe-item {
      width: 88px !important;
      height: 88px;
      margin-left: 14px;
      margin-top: 10px;
      img {
        width: 88px;
        height: 88px;
      }
    }
  }
  .blink-box-title {
    font-size: 28px;
    font-weight: 500;
    color: #222222;
    line-height: 40px;
    margin: 20px 0 40px 0;
  }
  .prize-box {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    span {
      color: #d23c65;
    }
    span:first-child {
      font-size: 22px;
      margin-top: 5px;
    }
    span:nth-child(2) {
      font-size: 40px;
    }
  }
}
</style>
